﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace yd.ControllerBase
{


    /// <summary>
    /// 重写视图查找引擎
    /// </summary>
    public class MyViewEngine : RazorViewEngine
    {

        // Fields
        internal static readonly string ViewStartFileName = "_ViewStart";

        // Methods
        public MyViewEngine()
            : this(null)
        {
        }

        public MyViewEngine(IViewPageActivator viewPageActivator)
            : base(viewPageActivator)
        {
            base.AreaViewLocationFormats = new string[] { "~/Areas/{2}/{1}/{0}.cshtml", "~/Areas/{2}/{1}/{0}.vbhtml", "~/Areas/{2}/Shared/{0}.cshtml", "~/Areas/{2}/Shared/{0}.vbhtml" };
            base.AreaMasterLocationFormats = new string[] { "~/Areas/{2}/{1}/{0}.cshtml", "~/Areas/{2}/{1}/{0}.vbhtml", "~/Areas/{2}/Shared/{0}.cshtml", "~/Areas/{2}/Shared/{0}.vbhtml" };
            base.AreaPartialViewLocationFormats = new string[] { "~/Areas/{2}/{1}/{0}.cshtml", "~/Areas/{2}/{1}/{0}.vbhtml", "~/Areas/{2}/Shared/{0}.cshtml", "~/Areas/{2}/Shared/{0}.vbhtml" };

            base.ViewLocationFormats = new string[] { "~/Areas/Views/{1}/{0}.cshtml", "~/Areas/Views/Shared/{0}.cshtml" };
            base.MasterLocationFormats = new string[] { "~/Areas/Views/{1}/{0}.cshtml", "~/Areas/Views/Shared/{0}.cshtml" };
            base.PartialViewLocationFormats = new string[] { "~/Areas/Views/{1}/{0}.cshtml", "~/Areas/Views/Shared/{0}.cshtml" };

            base.FileExtensions = new string[] { "cshtml", "vbhtml" };
        }

        protected override IView CreatePartialView(ControllerContext controllerContext, string partialPath)
        {
            string layoutPath = null;
            bool runViewStartPages = false;
            IEnumerable<string> fileExtensions = base.FileExtensions;
            return new RazorView(controllerContext, partialPath, layoutPath, runViewStartPages, fileExtensions, base.ViewPageActivator);
        }

        protected override IView CreateView(ControllerContext controllerContext, string viewPath, string masterPath)
        {
            string layoutPath = masterPath;
            bool runViewStartPages = true;
            IEnumerable<string> fileExtensions = base.FileExtensions;
            return new RazorView(controllerContext, viewPath, layoutPath, runViewStartPages, fileExtensions, base.ViewPageActivator);
        }

    }
}
